use crate::{netx::*, mem::*};

use std::{
    net::TcpStream,
};

/// 客户端
pub struct Client<Token>
{
    /// 用户数据
    pub token: Token,
    /// 使用的协议
    pub protocol: crate::netx::Protocol,
    /// xxx
    pub socket: crate::net::Socket,
    /// xxx
    pub recv_buf: *mut u8,
    /// xxx
    pub send_buf: *mut u8,
    /// xxx
    pub recv_buf_len: usize,
    /// xxx
    pub send_buf_len: usize,
    /// xxx
    pub recv_count: usize,
    /// xxx
    pub send_count: usize,
}
impl<Token> Client<Token>
{
    pub fn new(socket: TcpStream) -> Self
    {
        Client {
            token: unsafe { std::mem::zeroed::<Token>() },
            protocol: Protocol::TcpBinary,
            socket: 0,
            recv_buf: news(1024),
            send_buf: news(1024),
            recv_buf_len: 0,
            send_buf_len: 0,
            recv_count: 0,
            send_count: 0,
        }
    }
    pub fn new2(socket: TcpStream, buf_len: usize) -> Self
    {
        Client {
            token: unsafe { std::mem::zeroed::<Token>() },
            protocol: Protocol::TcpBinary,
            socket: 0,
            recv_buf: news(1024),
            send_buf: news(1024),
            recv_buf_len: 0,
            send_buf_len: 0,
            recv_count: 0,
            send_count: 0,
        }
    }
    pub fn send<T: NetSer>(&mut self, msg: T)
    {
        //let len = msg.to_bytes(&self.buf);
        //self.socket.peek(&mut self.buf[..len]);
    }
    pub fn call<T: NetSer, T2: NetSer>(&self, pak: T, callback: fn(T2))
    {
    }
    pub fn set_message(&self)
    {
    }
    pub fn bind_msg(&self)
    {
    }
}
